﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class SmsMtStatistic
    {
    	#region public properties
		[Required(ErrorMessage="MtGuid Required")]
		public Guid MtGuid { get; set; }
		public Guid? MoGuid { get; set; }
		[Required(ErrorMessage="Short Code Required")]
		public string ShortCode { get; set; }
		[Required(ErrorMessage="Dest Addr Required")]
		public string DestAddr { get; set; }
		[Required(ErrorMessage="OperatorID Required")]
		public int OperatorID { get; set; }
		[Required(ErrorMessage="Message Required")]
		public string Message { get; set; }
		[Required(ErrorMessage="CooperateID Required")]
		public int CooperateID { get; set; }
		[Required(ErrorMessage="Status Required")]
		public string Status { get; set; }
		[Required(ErrorMessage="Sent Time Required")]
		public DateTime SentTime { get; set; }
		public string CDRIndicator { get; set; }
		public string MTType { get; set; }
		public int? RetryOnFailReqTimes { get; set; }
		public int? RetryOnTimeOutReqTimes { get; set; }
		public long? RetryOnFailReqDuration { get; set; }
		public long? RetryOnTimeOutReqDuration { get; set; }
		#endregion

		#region constructor
		public SmsMtStatistic(){ }

		public SmsMtStatistic(IDataReader rd)
		{
			this.MtGuid = (Guid)rd["MtGuid"];
			this.MoGuid = rd["MoGuid"].Equals(DBNull.Value) ? (Guid?)null : (Guid)rd["MoGuid"];
			this.ShortCode = rd["ShortCode"].ToString();
			this.DestAddr = rd["DestAddr"].ToString();
			this.OperatorID = (int)rd["OperatorID"];
			this.Message = rd["Message"].ToString();
			this.CooperateID = (int)rd["CooperateID"];
			this.Status = rd["Status"].ToString();
			this.SentTime = (DateTime)rd["SentTime"];
			this.CDRIndicator = rd["CDRIndicator"].ToString();
			this.MTType = rd["MTType"].ToString();
			this.RetryOnFailReqTimes = rd["RetryOnFailReqTimes"].Equals(DBNull.Value) ? (int?)null : (int)rd["RetryOnFailReqTimes"];
			this.RetryOnTimeOutReqTimes = rd["RetryOnTimeOutReqTimes"].Equals(DBNull.Value) ? (int?)null : (int)rd["RetryOnTimeOutReqTimes"];
			this.RetryOnFailReqDuration = rd["RetryOnFailReqDuration"].Equals(DBNull.Value) ? (long?)null : (long)rd["RetryOnFailReqDuration"];
			this.RetryOnTimeOutReqDuration = rd["RetryOnTimeOutReqDuration"].Equals(DBNull.Value) ? (long?)null : (long)rd["RetryOnTimeOutReqDuration"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBSmsMtStatistic.Create(MtGuid, MoGuid, ShortCode, DestAddr, OperatorID, Message, CooperateID, Status, SentTime, CDRIndicator, MTType, RetryOnFailReqTimes, RetryOnTimeOutReqTimes, RetryOnFailReqDuration, RetryOnTimeOutReqDuration);
        }

        private bool Update()
        {
            return DBSmsMtStatistic.Update(MtGuid, MoGuid, ShortCode, DestAddr, OperatorID, Message, CooperateID, Status, SentTime, CDRIndicator, MTType, RetryOnFailReqTimes, RetryOnTimeOutReqTimes, RetryOnFailReqDuration, RetryOnTimeOutReqDuration);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(MtGuid != Guid.NewGuid())
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(Guid MtGuid)
        {
            return DBSmsMtStatistic.Delete(MtGuid);
        }

        public static List<SmsMtStatistic> GetAll()
        {
            return ObjectClass.CreateList<SmsMtStatistic>(DBSmsMtStatistic.GetAll());
        }

        public static SmsMtStatistic GetByKey(Guid MtGuid)
        {
            return ObjectClass.CreateInstance<SmsMtStatistic>(DBSmsMtStatistic.GetByKey(MtGuid));
        }

        public static List<SmsMtStatistic> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<SmsMtStatistic>(DBSmsMtStatistic.GetByTop(top, where, order));
        }
		#endregion
	}
}
